package com.shop.admin.dao.pink;

import com.shop.jpa.BaseDao;
import com.shop.domain.pink.AutoPink;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AutoPinkDao extends BaseDao<AutoPink, Long> {

    @Modifying(clearAutomatically = true)
    @Query(value = "insert into t_auto_pink(pink_id,uid,product_id,product_attr_value_id,order_no,status,create_time)" +
            "select p.pink_id,p.uid,p.product_id,p.product_attr_value_id,p.order_no,p.status,now() from t_store_pink p where p.pink_status=1 and p.pink_id=?1" +
            " and not exists (select 1 from t_auto_pink p1 where p1.order_no = p.order_no)",nativeQuery = true)
    int addAutoPinkByZj(Long pink_id);


    //查询待结算的拼团订单
    @Query(nativeQuery = true,value = "select p.* from t_auto_pink p where p.is_grade_level = 0 order by id asc limit ?1")
    List<AutoPink> findNeedGradeLevel(int limit);


    @Modifying(clearAutomatically = true)
    @Query("update AutoPink set isGradeLevel = 1 where id = ?1")
    public int updateUserLevelAutoPink(Long id);
}
